#
#  Copyright 2022 The Open Islands Authors. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
from pyoi.types import BaseType
from pyoi.util.base_utils import bytes_to_string


class FederatedPacketProperties(BaseType):
    def __init__(
            self,
            name=None,
            tag=None,
            format=None,
            delivery_mode=None,
            num_partitions=None,
            partition_size=None,
            packet_key=None,
    ) -> None:
        self.name = name
        self.tag = tag
        self.format = format
        self.delivery_mode = delivery_mode
        self.num_partitions = num_partitions
        self.partition_size = partition_size
        self.packet_key = packet_key

    @classmethod
    def from_dict(cls, d: dict):
        mp = FederatedPacketProperties()
        for k, v in d.items():
            setattr(mp, k, bytes_to_string(v) if isinstance(v, bytes) else v)
        return mp
